# Copyright 2024 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("//build_tools/bazel:build_defs.oss.bzl", "iree_compiler_cc_library", "iree_gentbl_cc_library", "iree_tablegen_doc", "iree_td_library")
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")

package(
    default_visibility = ["//visibility:public"],
    features = ["layering_check"],
    licenses = ["notice"],  # Apache 2.0
)

iree_td_library(
    name = "td_files",
    srcs = enforce_glob(
        [
            "EncodingAttrs.td",
            "EncodingBase.td",
            "EncodingInterfaces.td",
            "EncodingOps.td",
        ],
        include = ["*.td"],
    ),
    deps = [
        "//compiler/src/iree/compiler/Utils:td_files",
        "@llvm-project//mlir:BuiltinDialectTdFiles",
        "@llvm-project//mlir:InferTypeOpInterfaceTdFiles",
        "@llvm-project//mlir:OpBaseTdFiles",
        "@llvm-project//mlir:PDLDialectTdFiles",
        "@llvm-project//mlir:SideEffectInterfacesTdFiles",
    ],
)

iree_compiler_cc_library(
    name = "IR",
    srcs = [
        "EncodingAttrs.cpp",
        "EncodingAttrs.cpp.inc",
        "EncodingDialect.cpp",
        "EncodingDialect.cpp.inc",
        "EncodingEnums.cpp.inc",
        "EncodingInterfaces.cpp.inc",
        "EncodingOpInterfaces.cpp.inc",
        "EncodingOps.cpp",
        "EncodingOps.cpp.inc",
        "EncodingTypeInterfaces.cpp.inc",
        "EncodingTypes.cpp",
        "EncodingTypes.cpp.inc",
    ],
    hdrs = [
        "EncodingAttrs.h.inc",
        "EncodingDialect.h",
        "EncodingDialect.h.inc",
        "EncodingEnums.h.inc",
        "EncodingInterfaces.h.inc",
        "EncodingOpInterfaces.h.inc",
        "EncodingOps.h",
        "EncodingOps.h.inc",
        "EncodingTypeInterfaces.h.inc",
        "EncodingTypes.h",
        "EncodingTypes.h.inc",
    ],
    deps = [
        ":EncodingEnumsGen",
        ":EncodingInterfacesGen",
        ":EncodingOpsIncGen",
        ":EncodingTypesGen",
        "//compiler/src/iree/compiler/Dialect/TensorExt/IR",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:ArithDialect",
        "@llvm-project//mlir:DialectUtils",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:InferTypeOpInterface",
        "@llvm-project//mlir:InliningUtils",
        "@llvm-project//mlir:LinalgDialect",
        "@llvm-project//mlir:LinalgUtils",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TensorDialect",
        "@llvm-project//mlir:TensorUtils",
    ],
)

iree_gentbl_cc_library(
    name = "EncodingEnumsGen",
    tbl_outs = [
        (
            [
                "--gen-enum-decls",
                "--dialect=iree_encoding",
            ],
            "EncodingEnums.h.inc",
        ),
        (
            [
                "--gen-enum-defs",
                "--dialect=iree_encoding",
            ],
            "EncodingEnums.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "EncodingAttrs.td",
    deps = [":td_files"],
)

iree_gentbl_cc_library(
    name = "EncodingOpsIncGen",
    tbl_outs = [
        (
            ["--gen-op-decls"],
            "EncodingOps.h.inc",
        ),
        (
            ["--gen-op-defs"],
            "EncodingOps.cpp.inc",
        ),
        (
            [
                "--dialect=iree_encoding",
                "--gen-dialect-decls",
            ],
            "EncodingDialect.h.inc",
        ),
        (
            [
                "--dialect=iree_encoding",
                "--gen-dialect-defs",
            ],
            "EncodingDialect.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "EncodingOps.td",
    deps = [":td_files"],
)

iree_gentbl_cc_library(
    name = "EncodingInterfacesGen",
    tbl_outs = [
        (
            ["--gen-attr-interface-decls"],
            "EncodingInterfaces.h.inc",
        ),
        (
            ["--gen-attr-interface-defs"],
            "EncodingInterfaces.cpp.inc",
        ),
        (
            ["--gen-type-interface-decls"],
            "EncodingTypeInterfaces.h.inc",
        ),
        (
            ["--gen-type-interface-defs"],
            "EncodingTypeInterfaces.cpp.inc",
        ),
        (
            ["--gen-op-interface-decls"],
            "EncodingOpInterfaces.h.inc",
        ),
        (
            ["--gen-op-interface-defs"],
            "EncodingOpInterfaces.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "EncodingInterfaces.td",
    deps = [":td_files"],
)

iree_gentbl_cc_library(
    name = "EncodingTypesGen",
    tbl_outs = [
        (
            [
                "--gen-attrdef-decls",
                "--attrdefs-dialect=iree_encoding",
            ],
            "EncodingAttrs.h.inc",
        ),
        (
            [
                "--gen-attrdef-defs",
                "--attrdefs-dialect=iree_encoding",
            ],
            "EncodingAttrs.cpp.inc",
        ),
        (
            [
                "--gen-typedef-decls",
                "--typedefs-dialect=iree_encoding",
            ],
            "EncodingTypes.h.inc",
        ),
        (
            [
                "--gen-typedef-defs",
                "--typedefs-dialect=iree_encoding",
            ],
            "EncodingTypes.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "EncodingAttrs.td",
    deps = [":td_files"],
)

iree_tablegen_doc(
    name = "EncodingDialectDocGen",
    category = "Dialects",
    tbl_outs = [
        (
            [
                "--gen-dialect-doc",
                "-dialect=iree_encoding",
            ],
            "EncodingDialect.md",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "EncodingOps.td",
    deps = [":td_files"],
)
